#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS=hardening=+all
include /usr/share/dpkg/architecture.mk

BUILDDIR = obj-$(DEB_HOST_MULTIARCH)


CMAKE_FLAGS = -DCMAKE_BUILD_TYPE=RELEASE \
	-DCMAKE_INSTALL_PREFIX="/usr" \
	-DBUILD_EXAMPLES=OFF \
	-DBUILD_DOCS=OFF \
	-DBUILD_TESTS=OFF \
	-DBUILD_PERF_TESTS=OFF \
	-DOPENCV_ENABLE_NONFREE=ON \
	-DOPENCV_EXTRA_MODULES_PATH="$(CURDIR)/../contrib/modules" \
	-DBUILD_LIST=xfeatures2d ..

%:
	dh $@ --with python3 --parallel

override_dh_clean:
	rm -rvf modules/python/src2/hdr_parser.pyc
	rm -rvf modules/refman.rst

	dh_clean
	-rm -rvf modules/python/src2/__pycache__

override_dh_auto_clean:
	dh_auto_clean -B $(BUILDDIR)


override_dh_auto_configure: 
	dh_auto_configure -B $(BUILDDIR) \
		-- $(CMAKE_FLAGS) \
		-DCMAKE_SHARED_LINKER_FLAGS_RELEASE="$(LDFLAGS)" \
		-DWITH_V4L=OFF \
		-DWITH_LIBV4L=OFF \
		-DWITH_CUDA=OFF


override_dh_auto_build: 
	dh_auto_build -B $(BUILDDIR)
	dh_auto_build -B $(BUILDDIR)

override_dh_auto_test:

override_dh_auto_install:
	dh_auto_install -B $(BUILDDIR)

override_dh_install:
	dh_install
	dh_missing --fail-missing

override_dh_usrlocal:

PKG = opencv
UVER = $(shell dpkg-parsechangelog -S Version | sed 's,-.*,,')
DTYPE = +dfsg
VER  ?= $(subst $(DTYPE),,$(UVER))
get-orig-source:
	@echo "# OpenCV Downloading..."
	uscan --no-conf --verbose --force-download --download-version $(VER) --no-symlink
	@echo "# Packing..."
	mk-origtargz --repack --compression xz -S $(DTYPE) -C .. ../opencv_$(VER).orig.tar.gz -v $(VER)

	@echo "# OpenCV contrib Downloading..."
	uscan --no-conf --verbose --force-download --download-version $(VER) --no-symlink
	mk-origtargz --repack --compression xz -S $(DTYPE) -C .. ../opencv_$(VER).orig-contrib.tar.gz -v $(VER) -c contrib
